import { RUC_SERVICE } from '@/services/constant';
import { Request } from './axios-config';

//获取省，市，区
export const GetProvince = async () => {
  const res = await Request({
    method: 'GET',
    url: `${RUC_SERVICE}/ovCityInfo/getProvince`,
  });
  const data = res.data || [];
  return data.map(({ id, name }) => {
    return {
      label: name,
      value: id + '',
    };
  });
};
export const GetCities = async (id) => {
  const res = await Request({
    method: 'GET',
    url: `${RUC_SERVICE}/ovCityInfo/getCity?id=${id}`,
  });
  const data = res.data || [];
  return data.map(({ id, name }) => {
    return {
      label: name,
      value: id + '',
    };
  });
};
export const GetAreas = async (id) => {
  const res = await Request({
    method: 'GET',
    url: `${RUC_SERVICE}/ovCityInfo/getArea?id=${id}`,
  });
  const data = res.data || [];
  return data.map(({ id, name }) => {
    return {
      label: name,
      value: id + '',
    };
  });
};

// 获取职业代码
export const GetOccupationCode = async () => {
  const res = await Request({
    method: 'GET',
    url: `${RUC_SERVICE}/specialtyCode/v1/specialtyCode/list`,
  });
  const data = res.data || [];
  return data.map(({ id, name }) => {
    return {
      label: name,
      value: id + '',
    };
  });
};

//获取证件类型
export const GetCardTypeCode = async () => {
  const res = await Request({
    method: 'POST',
    url: `${RUC_SERVICE}/rucCertificateType/getCertificateType`,
  });
  const data = res.data || [];
  return data.map(({ id, name }) => {
    return {
      label: name,
      value: id + '',
    };
  });
};
//获取国家
export const GetCountryCode = async () => {
  const res = await Request({
    method: 'POST',
    url: `${RUC_SERVICE}/rucCountryCode/getCountryCode`,
  });
  const data = res.data || [];
  return data.map(({ id, name }) => {
    return {
      label: name,
      value: id + '',
    };
  });
};

//获取开户行地区
export const GetBankArea = async () => {
  const res = await Request({
    url: `${RUC_SERVICE}/rucBankArea/v1/rucBankArea/list`,
  });
  const data = res.data || [];
  return data.map(({ id, name }) => {
    return {
      label: name,
      value: name + '',
    };
  });
};

//获取开户行
export const GetBanks = async (id) => {
  // 没有地区参数，不请求
  if (!id) {
    return;
  }
  const res = await Request({
    url: `${RUC_SERVICE}/rucBank/v1/rucBank/list/${id}`,
  });
  const data = res.data || [];
  return data.map(({ id, name }) => {
    return {
      label: name,
      value: name + '',
    };
  });
};

// 用户是否进行过短信验证
export const isCheckedAuth = async () => {
  const res = await Request({
    url: `${RUC_SERVICE}/signAuth/isAuth`,
    method: 'GET',
  });
  return res;
};

// 发送短信验证码
export const sendVerificationCode = async () => {
  const res = await Request({
    url: `${RUC_SERVICE}/smsCode/user/sendVerifyCode`,
    method: 'POST',
  });
  return res;
};

// 验证短信验证码
export const checkVerificationCode = async (data) => {
  const res = await Request({
    url: `${RUC_SERVICE}/smsCode/user/verifyCode?code=${data}`,
    method: 'POST',
  });
  return res;
};

// 查询当前用户协议状态
export const getAgreementStatus = () => {
  return Request({
    url: `${RUC_SERVICE}/api/agreement/v1/query/agreementStatus`,
    method: 'GET',
  });
};

// 同意协议
export const agreement = () => {
  return Request({
    url: `${RUC_SERVICE}/api/agreement/v1/agree/agreementStatus`,
    method: 'GET',
  });
};
